<?php use_helper('I18N', 'Date') ?>
<?php use_helper('Object') ?>
<title><?= $sf_response->getTitle() ?></title>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">

<div id="sf_admin_bar">

<div class="sf_admin_filters">
<?php echo form_tag('component/viewWarehouse', array('method' => 'get')) ?>

  <fieldset>
    <h2>filters</h2>
    <div class="form-row">
    <label for="filters_productcode">Product Code:</label>
    <div class="content">
    <?php echo input_tag('filters[productcode]', isset($filters['productcode']) ? $filters['productcode'] : null, array (
  'size' => 25,
)) ?>
    </div>
    </div>

        <div class="form-row">
    <label for="filters_description">Description:</label>
    <div class="content">
    <?php echo input_tag('filters[description]', isset($filters['description']) ? $filters['description'] : null, array (
  'size' => 25,
)) ?>
    </div>
    </div>

        <div class="form-row">
    <label for="filters_category">Category:</label>
    <div class="content">    
    <select name="filters[category]" id="filters_category">
    <option value=""></option>     
    <?php foreach (CommonValues::$gCompCategory['key'] as $key=>$category) { ?>
    <option value="<?php echo $key;  if (isset($filters['category']) &&  ($key == $filters['category']) ) echo '" selected="selected';?>"><?php echo $key ?></option>
    <?php } ?>
    </select>
    </div>
    </div>

    <div class="form-row">
    <label for="filters_description">Brand:</label>
    <div class="content">
    <?php echo input_tag('filters[brand]', isset($filters['brand']) ? $filters['brand'] : null, array (
  'size' => 25,
)) ?>
    </div>
    </div>

      </fieldset>

  <ul class="sf_admin_actions">
    <li><?php echo button_to('reset', 'component/viewWarehouse?filter=filter', 'class=sf_admin_action_reset_filter') ?></li>
    <li><?php echo submit_tag('filter', 'name=filter class=sf_admin_action_filter') ?></li>
  </ul>

</form>
</div>
</div>
</div>
<div id="sf_admin_container">
<table id ='components' cellspacing="0" class="sf_admin_list" >
<?php  
if (isset($componentList) && count($componentList)&& ( ($pagenumber-1)*$maxperpage < count($componentList)) ) 
{ ?>
<thead>
<tr>
        <th id="sf_admin_list_th_productcode" width="15%">Product Code</th>      
        <th id="sf_admin_list_th_productcode" width="20%">Description</th>
        <th id="sf_admin_list_th_productcode" width="7%">Unit</th>
        <th id="sf_admin_list_th_productcode" width="7%">Brand</th>
        <th id="sf_admin_list_th_productcode" width="7%">Category</th>
        <th id="sf_admin_list_th_description" style="text-align:right" >Opening</th>
      <th id="sf_admin_list_th_description"   style="text-align:right" >Total In</th>       
      <th id="sf_admin_list_th_description"   style="text-align:right" >Total Out</th>
      <th id="sf_admin_list_th_description"   style="text-align:right">Closing</th>
      <th id="sf_admin_list_th_description"   style="text-align:right">Qty Needed</th>
      <th id="sf_admin_list_th_description"   style="text-align:right">Qty Requested</th>
      <th id="sf_admin_list_th_description"   style="text-align:right">Qty Ordered</th>
</tr>
</thead>
<?
    $TotalOpening =0;
    $TotalIn =0;
    $TotalOut =0;
    $TotalClosing =0;
    $TotalNeeded =0;
    $TotalRequested =0;
    $TotalOrdered =0;
    
    $count = count($componentList);
    
    $countWH = count($WHList);
    for($i = 0; $i < $countWH; $i++)
    {
        $warehouse = $WHList[$i];
        $TotalOpening += $warehouse->getOpening();
        $TotalIn += $warehouse->getTotalin();
        $TotalOut += $warehouse->getTotalout();
        $TotalClosing += $warehouse->getClosing();
        $TotalNeeded += $warehouse->getQtyneeded();
        $TotalRequested += $warehouse->getQtyrequested();
        $TotalOrdered += $warehouse->getQtyordered();
    }
    
    $i =($pagenumber-1)*$maxperpage;
?>

<tr class="sf_admin_row_1" style="color:#CC0000">
    <td width="15"><b>TOTAL</b></td>
    <td width="0%"></td>
    <td width="0%"></td>
    <td width="0%"></td>
    <td width="0%"></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalOpening)?></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalIn)?></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalOut)?></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalClosing)?></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalNeeded)?></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalRequested)?></td>
    <td style="text-align:right"><?echo CommonValues::FormatCurrency($TotalOrdered)?></td>
</tr>

<!--show component here-->
<?
    $IsAdmin = $sf_user->hasGroup('Administrator') == true;
    for(; $i < $count && $i < $pagenumber*$maxperpage; $i++) { 
        $component = $componentList[$i];
        $warehouse = $component->getWarehouse();
?>
        <tr class="sf_admin_row_<?php echo $i%2?>">
            <td><?if ($hasEditCompPermission) echo link_to($component->getProductcode(), 'component/edit?id='.$component->getId());
            else echo link_to($component->getProductcode(), 'component/view?id='.$component->getId()) ?></td>
            <td><?echo $component->getDescription()?></td>
            <td><?echo $component->getComponentUnit()?></td>
            <td><?echo $component->getBrand()?></td>
            <td ><?echo CommonValues::$gCompCategorySimple['value'][$component->getCategory()] // $component->getBrand()?></td>
            <td style="text-align:right"><?echo  CommonValues::FormatCurrency($warehouse->getOpening())?></td>
            <td style="text-align:right"><?echo  CommonValues::FormatCurrency($warehouse->getTotalin())?></td>
            <td style="text-align:right"><?echo  CommonValues::FormatCurrency($warehouse->getTotalout())?></td>
            <td style="text-align:right"><?
            if (!$IsAdmin)
                    echo CommonValues::FormatCurrency($warehouse->getClosing());
            else
                echo link_to(CommonValues::FormatCurrency($warehouse->getClosing()), 'component/changeQty?type=closing&id='.$component->getId(), array (

  'confirm' => __('WARNING: Are you sure you want to change this closing?'),
));
            ?></td>
            <td style="text-align:right"><?
            if (!$IsAdmin)
                    echo CommonValues::FormatCurrency($warehouse->getQtyneeded());
            else
                echo link_to(CommonValues::FormatCurrency($warehouse->getQtyneeded()), 'component/changeQty?type=needed&id='.$component->getId(), array (

  'confirm' => __('WARNING: Are you sure you want to change this qty need?'),
));
            ?></td>
            <td style="text-align:right"><?
            if (!$IsAdmin)
                    echo CommonValues::FormatCurrency($warehouse->getQtyrequested());
            else
                echo link_to(CommonValues::FormatCurrency($warehouse->getQtyrequested()), 'component/changeQty?type=requested&id='.$component->getId(), array (

  'confirm' => __('WARNING: Are you sure you want to change this qty requested?'),
));
            ?></td>
            <td style="text-align:right"><?
            if (!$IsAdmin)
                    echo CommonValues::FormatCurrency($warehouse->getQtyordered());
            else
                echo link_to(CommonValues::FormatCurrency($warehouse->getQtyordered()), 'component/changeQty?type=ordered&id='.$component->getId(), array (

  'confirm' => __('WARNING: Are you sure you want to change this qty ordered?'),
));
            ?></td>   
        </tr>
<?php } ?> 

<tfoot>
<tr><th colspan="12">
<div class="float-right">
  <?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/first.png', array('align' => 'absmiddle', 'alt' =>'First', 'title' =>'First')), 'component/viewWarehouse?page=1') ?>
  <?php 
    $previouspage = $pagenumber -1? $pagenumber -1 :1;
    
    echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/previous.png', array('align' => 'absmiddle', 'alt' =>'Previous', 'title' =>'Previous')), 'component/viewWarehouse?page='.$previouspage) ;
    if ($pagenumber -1 > 0) 
        echo link_to($previouspage, 'component/viewWarehouse?page='.$previouspage);     ?>
    <?php 
    echo $pagenumber?>
  <?php 
    $nextpage = $pagenumber*$maxperpage < $count ? $pagenumber +1 :$pagenumber;
    if ($pagenumber*$maxperpage < $count) 
        echo link_to($nextpage, 'component/viewWarehouse?page='.$nextpage);     
    echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/next.png', array('align' => 'absmiddle', 'alt' =>'Next', 'title' =>'Next')), 'component/viewWarehouse?page='.$nextpage) ?>
  <?php 
      $lastpage = intval(($count+ $maxperpage -1)/$maxperpage);
      echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/last.png', array('align' => 'absmiddle', 'alt' =>'Last', 'title' =>'Last')), 'component/viewWarehouse?page='.$lastpage) ?>
<? }?>
</div>
<?php 
    $count = count($componentList)? count($componentList) : 0;
    echo format_number_choice('[0] no result|[1] 1 result|(1,+Inf] %1% results', array('%1%' => $count), $count) ?>
</th></tr>
</tfoot>    
</table>
</div>
<? CalcTime::ShowTime(true);?>
